class MyCircularQueue {

    private int[] elem;
    private int front;//表示队列的头
    private int rear;//表示队列的尾

    public MyCircularQueue(int k) {
        //this.elem = new int[k];
        //如果是浪费空间 这里必须处理多加一个1
        this.elem = new int[k + 1];
    }

    //入队列
    public boolean enQueue(int value) {
        //1.检查是否队列是满的
        if (isFull()) {
            return false;


        }
        //2.
        elem[rear] = value;
        //rear++;
        rear = (rear + 1) % elem.length;
        return true;
    }

    //出队列
    public boolean deQueue() {
        if (isEmpty()) {
            return false;
        }
        //front++;
        front = (front + 1) % elem.length;
        return true;
    }

    //得到队头元素
    public int Front() {
        if (isEmpty()) {
            return -1;
        }
        return elem[front];
    }

    //得到队尾元素
    public int Rear() {
        if (isEmpty()) {
            return -1;
        }
        int index = (rear == 0) ? elem.length - 1 : rear - 1;
        return elem[index];
    }

    public boolean isEmpty() {
        return front == rear;
    }

    //队列是否为满
    public boolean isFull() {
//        if((rear + 1) % elem.length == front) {
//            return true;
//        }
//        return false;
//    }
        return (rear + 1) % elem.length == front;
    }
}